package com.lanjiu.lib.imclient.dto.notify;

import com.lanjiu.pro.business.BusinessProtocolEntities;
import com.lanjiu.lib.imclient.dto.base.Dto;
import com.lanjiu.lib.imclient.ims.IMSContacts;

/**
 * @description: 通知
 * @author: Panwei
 * @date: 2019/11/14 22:00
 */
public class NotifyDto extends Dto {

    // 消息类型（好友/群组）
    private int notifyType;

    // 好友申请通知实体
    private FriendNotifyDto friendNotify;

    // 群通知
    private GroupNotifyDto groupNotify;

    public NotifyDto() {
    }

    public int getNotifyType() {
        return notifyType;
    }

    public void setNotifyType(int notifyType) {
        this.notifyType = notifyType;
    }

    public FriendNotifyDto getFriendNotify() {
        return friendNotify;
    }

    public void setFriendNotify(FriendNotifyDto friendNotify) {
        this.friendNotify = friendNotify;
    }

    public GroupNotifyDto getGroupNotify() {
        return groupNotify;
    }

    public void setGroupNotify(GroupNotifyDto groupNotify) {
        this.groupNotify = groupNotify;
    }

    public NotifyDto(BusinessProtocolEntities.TouristsNotify notify) {
        this.notifyType = notify.getNotifyType();
        if (IMSContacts.Type.NOTIFY_FRIEND == notifyType)
            this.friendNotify = new FriendNotifyDto(notify.getFriendNotify());
        else
            this.groupNotify = new GroupNotifyDto(notify.getGroupNotify());
    }

    public NotifyDto(BusinessProtocolEntities.RegisteredNotify notify) {
        this.notifyType = notify.getNotifyType();
        if (IMSContacts.Type.NOTIFY_FRIEND == notifyType)
            this.friendNotify = new FriendNotifyDto(notify.getFriendNotify());
        else
            this.groupNotify = new GroupNotifyDto(notify.getGroupNotify());
    }

    @Override
    public Object toProtobuf() {
        if (IMSContacts.Type.NOTIFY_FRIEND == notifyType) {
            if (IMSContacts.UserType.REGISTERED_USER.equals(friendNotify.getFriend().getCurrentUserType())) {
                BusinessProtocolEntities.RegisteredNotify.Builder builder = BusinessProtocolEntities.RegisteredNotify.newBuilder();
                builder.setNotifyType(notifyType);
                if (null != friendNotify)
                    builder.setFriendNotify((BusinessProtocolEntities.RegisteredFriendNotify) friendNotify.toProtobuf());
                return builder.build();
            } else {
                BusinessProtocolEntities.TouristsNotify.Builder builder = BusinessProtocolEntities.TouristsNotify.newBuilder();
                builder.setNotifyType(notifyType);
                if (null != friendNotify)
                    builder.setFriendNotify((BusinessProtocolEntities.TouristsFriendNotify) friendNotify.toProtobuf());
                return builder.build();
            }
        } else {
            if (IMSContacts.UserType.REGISTERED_USER.equals(groupNotify.getGroupMember().getCurrentUserType())) {
                BusinessProtocolEntities.RegisteredNotify.Builder builder = BusinessProtocolEntities.RegisteredNotify.newBuilder();
                builder.setNotifyType(notifyType);
                if (null != groupNotify)
                    builder.setGroupNotify((BusinessProtocolEntities.RegisteredGroupNotify) groupNotify.toProtobuf());
                return builder.build();
            } else {
                BusinessProtocolEntities.TouristsNotify.Builder builder = BusinessProtocolEntities.TouristsNotify.newBuilder();
                builder.setNotifyType(notifyType);
                if (null != groupNotify)
                    builder.setGroupNotify((BusinessProtocolEntities.TouristsGroupNotify) groupNotify.toProtobuf());
                return builder.build();
            }
        }
    }
}
